package cn.bingo.yunsj.controller;

import cn.bingo.yunsj.common.exception.EmException;
import cn.bingo.yunsj.common.exception.OwnException;
import cn.bingo.yunsj.controller.model.SerachModel;
import cn.bingo.yunsj.domain.RpSuccess;
import cn.bingo.yunsj.common.result.Response;
import cn.bingo.yunsj.service.SendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@Api("邮箱已发送控制器")
@RequestMapping(value = "/send")
@CrossOrigin
public class SuccessController {

    @Autowired
    private SendService sendService;

    @RequestMapping(value = "/All", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取所有信息")
    public Response getAll() {
        return sendService.getAll();
    }

    @RequestMapping(value = "/name",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取发送成功里面得所有模板种类")
    public Response getName(){
        return sendService.getName();
    }

  @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("根据已发送人搜索")
    public Response search(SerachModel serachModel) {
        if(serachModel==null){
            throw new OwnException(EmException.PARAM_EXCPTION);
        }
        String start = "";
        if(serachModel.getStartTime()!=null) {
            start = serachModel.getStartTime().substring(0, serachModel.getStartTime().indexOf("T"));
        }
        String end = "";
        if(serachModel.getEndTime()!=null) {
            end = serachModel.getEndTime().substring(0, serachModel.getEndTime().indexOf("T"));
        }
        return sendService.search(serachModel, start, end);
    }
}
